package com.talent.web.config.minio;

import io.minio.MinioAsyncClient;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: hszhou
 * @Date: 2025/3/1 15:13
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@Configuration
@ConditionalOnProperty(name = "minio.enabled",havingValue = "true")
public class MinioConfig {


    @Autowired
    private TlMinioProperties tlMinioProperties;

    @Bean
    public MinioClient minioClient(){
        return MinioClient.builder()
                .endpoint(tlMinioProperties.getEndPoint())
                .credentials(tlMinioProperties.getAccessKey(), tlMinioProperties.getSecretKey()).build();
   }

    /**
     * 配置用于分片上传的Minio连接客户端
     */
    @Bean
    public TlMinioClient tlMinioClient() {
        return new TlMinioClient(
                MinioAsyncClient.builder()
                        .endpoint(tlMinioProperties.getEndPoint())
                        .credentials(tlMinioProperties.getAccessKey(), tlMinioProperties.getSecretKey())
                        .build()
        );
    }

}
